<%- include('../include/header.ejs') %>

<style type="text/css">
 .row{
    width: 80%;
    min-height: 80%;
    margin:10px auto;
}
h2{
    font-size: 20px;
    line-height: 40px;
}
</style>
<section id="service" class="hSize">
    <div class="container">
        <div class="row">
            <div class="page-header">
                <h2>场景列表</h2>
                <a href="/creat3D"><h5 style="color: #06cc9b;">点击跳转在线生成页面</h5></a>
            </div>
            <% var SightMsgs %>
            <% if(SightMsgs && SightMsgs.length>0){ %>
                <table class="table table-hover table-bordered text-center">
                    <thead>
                        <tr>
                            <td>序号</td>
                            <td>标题</td>
                            <td>预览</td>
                            <td>删除</td>
                        </tr>
                    </thead>
                    <tbody>

                        <% for(var i=0;i<SightMsgs.length;i++){%>
                            <tr class="SightMsgs<%=SightMsgs[i]._id%>">
                                <td><%=i %></td>
                                <td><%=SightMsgs[i].title %></td>
                                <td>
                                    <a href="/items/<%=SightMsgs[i]._id%>" target="_blank">查看</a>
                                </td>
                                <td><button type="button " class="btn btn-danger dlsight" data-id="<%=SightMsgs[i]._id%>" >删除</button></td>
                            </tr>
                            <%} %>
                        </tbody>
                    </table>
                    <%}else{%>
                      <h4 style="text-align:center;">数据表里啥也没有。。。<a href="/creat3D" type="button" style="color: #06cc9b;" >点我添加</a>吧^-^</h4>
                      <%}%>
                  </div>
              </div>
          </section>
          <script>
            $(function(){
                $(".dlsight").click(function(e){ delitem(e,"SightMsgs")});
            });
            function delitem (e,url){
                var target=$(e.target);
                var id=target.data("id");
                var tr=$("."+url+id);
                $.ajax({
                    type:"delete",
                    url:"/delete/"+url+"?id="+id
                })
                .done(function(results){
                    if(results.success===1){
                        if(tr.length>0){
                            tr.remove();
                        }
                    }
                });
            }
        </script>
        <%- include('../include/footer.ejs') %>
